﻿Imports System.Data.OleDb
Public Class PhongChieuDAO
    Public Function Insert(ByVal tmp As PhongChieuDTO) As Integer
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = "insert into PHONGCHIEU (MaRap, SoDayGhe, SoHangGhe, MoTa, DKKT, TinhTrang ) values (@MaRap, @SoDayGhe, @SoHangGhe, @MoTa, @DKKT, @TinhTrang)"
        Dim cmd As OleDbCommand = New OleDbCommand(str, cn)

        Dim para1, para2, para3, para4, para5, para6 As OleDbParameter
        para1 = New OleDbParameter("@MaRap", tmp.MaRap)
        cmd.Parameters.Add(para1)
        para2 = New OleDbParameter("@SoDayGhe", tmp.SoDayGhe)
        cmd.Parameters.Add(para2)
        para3 = New OleDbParameter("@SoHangGhe", tmp.SoHangGhe)
        cmd.Parameters.Add(para3)
        para4 = New OleDbParameter("@MoTa", tmp.MoTa)
        cmd.Parameters.Add(para4)
        para5 = New OleDbParameter("@DKKT", tmp.DKKT)
        cmd.Parameters.Add(para5)
        para6 = New OleDbParameter("@TinhTrang", tmp.TinhTrang)
        cmd.Parameters.Add(para6)


        Dim result As Integer = cmd.ExecuteNonQuery()
        cn.Close()
        Return result
    End Function

    Public Function Update(ByVal tmp As PhongChieuDTO) As Integer
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = "update PHONGCHIEU set MaRap=@MaRap,SoDayGhe=@SoDayGhe,SoHangGhe=@SoHangGhe,MoTa=@MoTa,DKKT=@DKKT,TinhTrang=@TinhTrang where MaPhongChieu=@MaPhongChieu"
        Dim cmd As OleDbCommand = New OleDbCommand(str, cn)

        Dim para1, para2, para3, para4, para5, para6, para7 As OleDbParameter

        para2 = New OleDbParameter("@MaRap", tmp.MaRap)
        cmd.Parameters.Add(para2)
        para3 = New OleDbParameter("@SoDayGhe", tmp.SoDayGhe)
        cmd.Parameters.Add(para3)
        para4 = New OleDbParameter("@SoHangGhe", tmp.SoHangGhe)
        cmd.Parameters.Add(para4)
        para5 = New OleDbParameter("@MoTa", tmp.MoTa)
        cmd.Parameters.Add(para5)
        para6 = New OleDbParameter("@DKKT", tmp.DKKT)
        cmd.Parameters.Add(para6)
        para7 = New OleDbParameter("@TinhTrang", tmp.TinhTrang)
        cmd.Parameters.Add(para7)
        para1 = New OleDbParameter("@MaPhongChieu", tmp.MaPhongChieu)
        cmd.Parameters.Add(para1)
        Dim result As Integer = cmd.ExecuteNonQuery()
        cn.Close()
        Return result
    End Function

    Public Function Delete(ByVal tmp As PhongChieuDTO) As Integer
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = "delete from PHONGCHIEU where MaPhongChieu=@MaPhongChieu"
        Dim cmd As OleDbCommand = New OleDbCommand(str, cn)

        Dim para1 As OleDbParameter
        para1 = New OleDbParameter("@MaPhongChieu", tmp.MaPhongChieu)
        cmd.Parameters.Add(para1)

        Dim result As Integer = cmd.ExecuteNonQuery()
        cn.Close()
        Return result
    End Function


    Public Function GetTable(ByVal t As String) As DataTable
        Dim dt As DataTable = New DataTable()
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = t
        Dim da As OleDbDataAdapter = New OleDbDataAdapter(str, cn)
        da.Fill(dt)
        cn.Close()
        Return dt
    End Function
    Public Function GetValue(ByVal t As String) As String
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = t
        Dim cmd As OleDbCommand = New OleDbCommand(str, cn)
        Dim kq As String = cmd.ExecuteScalar()
        Return kq
    End Function
End Class
